<template>
    <BasicForm @register="workConfigForm" @submit="submitform()">
    </BasicForm>
</template>
<script lang="ts">
  import { ref, defineComponent } from 'vue';
  import { getProjectParams } from '/@/api/setParam/setParams'
  import { BasicForm, FormSchema, useForm } from '/@/components/Form';
  import { Select } from 'ant-design-vue';
  const valueSelectA = ref<string[]>([]);
  const rolesOptions = ref<Recordable[]>([]);
export default defineComponent({
  name:'wxapikey',
  components: {  
      BasicForm,
      ASelect: Select
    },
  emits: ['saveparam',],
  setup(_, { emit }) {
    const workconfigKeyValue = ref<Recordable>({})
    const wxschemas: FormSchema[] = [
       {
          field: 'AppID',
          label: '小程序ID',
          component: 'Input',
          helpMessage: '小程序ID key:AppID',
          required: true,
          colProps: { span: 12 },
        },
        {
          field: 'AppSecret',
          label: '小程序密钥',
          component: 'Input',
          helpMessage: '小程序密钥 key:AppSecret',
          required: true,
          colProps: { span: 12 },
        },
        {
          field: 'serviceAPPid',
          label: '服务号APPid',
          component: 'Input',
          helpMessage: '服务号APPid key:serviceAPPid',
          colProps: { span: 12 },
        },
        {
          field: 'serviceSecretKey',
          label: '服务号secretKey',
          component: 'Input',
          helpMessage: '服务号serviceSecretKey key:serviceSecretKey',
          colProps: { span: 12 },
        },
        {
          field: 'mchid',
          label: '支付商户号',
          component: 'Input',
          helpMessage: '支付商户号 key:mchid',
          colProps: { span: 12 },
        },
        {
          field: 'payScrectKey',
          label: '支付密钥',
          component: 'Input',
          helpMessage: '支付密钥 key:payScrectKey',
          colProps: { span: 12 },
        },
        {
          field: 'serial_no',
          label: '证书序列号',
          component: 'Input',
          helpMessage: '证书序列号 key:serial_no',
          colProps: { span: 12 },
        },
       ];
      const workConfigForm = useForm({
      labelWidth: 250,
      schemas: wxschemas,
      showActionButtonGroup: true,
      submitButtonOptions:{
        text:'保存'
      },
      actionColOptions: {
        span: 23,
      },
    });
      //获取wxkeyForm,改变form的值
      getProjectParams({param_type:'wxapiKey'}).then(async (data) =>{
        console.log(data)
        workconfigKeyValue.value = JSON.parse(data.data)
        await workConfigForm[1].setFieldsValue(workconfigKeyValue.value)
      })
      async function submitform(){
        const { validate } = workConfigForm[1]
        const values = await validate();
        const update_data = {
          "key":'wxapiKey',
          "value":JSON.stringify({
            AppID: values.AppID,
            AppSecret: values.AppSecret,
            mchid: values.mchid,
            serviceAPPid: values.serviceAPPid,
            payScrectKey: values.payScrectKey,
            serial_no: values.serial_no,
            serviceSecretKey: values.serviceSecretKey,
          })
        }
        emit('saveparam',{value:update_data})
      }
    return {
      workConfigForm,
      workconfigKeyValue,
      submitform,
      valueSelectA,
      rolesOptions,
    }
  },
})
</script>
